//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
//     Copyright (c) Telligent Systems Corporation.  All rights reserved.
// </copyright> 
//------------------------------------------------------------------------------

using System.Collections;
using System.Collections.Specialized;
using System.IO;
using System.Web.Caching;
using CommunityServer.Blogs.Components;
using CommunityServer.Components;
using CommunityServer.Configuration;
using CommunityServer.Controls;

namespace CommunityServer.Blogs.Controls
{
	/// <summary>
	/// Summary description for ThemeManager.
	/// </summary>
    public class ThemeManager : BaseThemeManager
    {
        private NameValueCollection SkinList = new NameValueCollection();
        private Hashtable ThemeList = new Hashtable();
        public static string CacheKey = "WeblogThemeManager";
        private ThemeManager()
        {

        }

        public static ThemeManager Instance()
        {
            ThemeManager tm = CSCache.Get(CacheKey) as ThemeManager;
            if (tm == null)
            {
                tm = new ThemeManager();
                CacheDependency dep = new CacheDependency(null, new string[] { CSConfiguration.CacheKey });
                CSCache.Insert(CacheKey, tm, dep);
            }

            return tm;
        }

        protected override ThemedApplicationKeyApplicationConfiguration Config
        {
            get { return WeblogConfiguration.Instance(); }
        }


        public static string SkinPath()
        {
            CSContext cntx = CSContext.Current;
            if (cntx.IsWebRequest)
            {
                Weblog blog = Weblogs.GetWeblog(cntx.ApplicationKey);
                string path = WeblogConfiguration.Instance().ThemeLocation + blog.Theme + "/";
                if (path.EndsWith("/"))
                    path = path.Substring(0, path.Length - 1);
                return path.Replace("~", Globals.ApplicationPath);
            }
            else
                return string.Empty;
        }
    }		
}
